rst = 0;
clk=0;#10;clk=1;#10;
rst = 1;

instruction= 16'b0011000000111001, // @12345
clk=0;#10;clk=1;#10;
instruction= 16'b1110110000010000, // D=A
clk=0;#10;clk=1;#10;
instruction= 16'b0101101110100000, // @23456
clk=0;#10;clk=1;#10;
instruction= 16'b1110000111111000, // ADM=A-D
clk=0;#10;clk=1;#10;

assert(outM === 'd11111) else $error("23456 - 12345 failed");
assert(writeM === 1'b1) else $error("writeM failed");
assert(addressM === 'd23456) else $error("addressM failed");
assert(pc === 4) else $error("pc == 4 failed");

instruction= 16'b0000001111101011, // @1003
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100001000, // M=D
clk=0;#10;clk=1;#10;

instruction= 16'b0000001111101100, // @1004
clk=0;#10;clk=1;#10;

instruction= 16'b1110001110011000, // MD=D-1
clk=0;#10;clk=1;#10;

instruction= 16'b0000001111101000, // @1000
clk=0;#10;clk=1;#10;

instruction= 16'b1111010011110000, // AD=D-M
inM = 11111;
clk=0;#10;clk=1;#10;

instruction= 16'b0000000000001110, // @14
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000100, // D;jlt
clk=0;#10;clk=1;#10;

instruction= 16'b0000001111100111, // @999
clk=0;#10;clk=1;#10;

instruction= 16'b1111110111100000, // A=M+1
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100101000, // AM=D
clk=0;#10;clk=1;#10;

instruction= 16'b0000000000010101, // @21
clk=0;#10;clk=1;#10;

instruction= 16'b1110011111000010, // D+1;jeq
clk=0;#10;clk=1;#10;

instruction= 16'b0000000000000010, // @2
clk=0;#10;clk=1;#10;

instruction= 16'b1110000010111000, // AMD=D+A
clk=0;#10;clk=1;#10;

instruction= 16'b1111110111001000, // M=M+1
clk=0;#10;clk=1;#10;

instruction= 16'b1111110010101000, // AM=M-1
clk=0;#10;clk=1;#10;

instruction= 16'b0000001111101000, // @1000
clk=0;#10;clk=1;#10;

instruction= 16'b1110111010010000, // D=-1
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000001, // D;JGT
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000010, // D;JEQ
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000011, // D;JGE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000100, // D;JLT
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000101, // D;JNE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000110, // D;JLE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000111, // D;JMP
clk=0;#10;clk=1;#10;

instruction= 16'b1110101010010000, // D=0
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000001, // D;JGT
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000010, // D;JEQ
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000011, // D;JGE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000100, // D;JLT
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000101, // D;JNE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000110, // D;JLE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000111, // D;JMP
clk=0;#10;clk=1;#10;

instruction= 16'b1110111111010000, // D=1
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000001, // D;JGT
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000010, // D;JEQ
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000011, // D;JGE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000100, // D;JLT
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000101, // D;JNE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000110, // D;JLE
clk=0;#10;clk=1;#10;

instruction= 16'b1110001100000111, // D;JMP
clk=0;#10;clk=1;#10;

reset = 1;
clk=0;#10;clk=1;#10;

instruction= 16'b0111111111111111, // @32767
reset = 1
clk=0;#10;clk=1;#10;
